<template>
  <div class="app-container">

    <!-- 搜索工作栏 -->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="90px">
      <el-form-item label="订单号" prop="orderNo">
        <el-input v-model="queryParams.orderNo" placeholder="请输入订单编号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="商户订单编号" prop="merchantOrderNo" label-width="100px">
        <el-input v-model="queryParams.merchantOrderNo" placeholder="请输入商户订单编号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="商品编码" prop="productCode">
        <el-input v-model="queryParams.productCode" placeholder="请输入商品编码" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="验机状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择验机状态" clearable size="small">
          <el-option v-for="dict in statusDictDatas" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="IMEI" prop="imei">
        <el-input v-model="queryParams.imei" placeholder="请输入IMEI" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="销售人员" prop="saleUserName">
        <el-input v-model="queryParams.saleUserName" placeholder="请输入销售人员名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="验机人员" prop="checkUserName" label-width="100px">
        <el-input v-model="queryParams.checkUserName" placeholder="请输入验机人员" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="入库时间" prop="inboundTime">
        <el-date-picker v-model="queryParams.inboundTime" style="width: 240px" value-format="yyyy-MM-dd HH:mm:ss" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"
          :default-time="['00:00:00', '23:59:59']" />
      </el-form-item>
      <el-form-item label="验机完成时间" prop="finishTime" label-width="100px">
        <el-date-picker v-model="queryParams.finishTime" style="width: 240px" value-format="yyyy-MM-dd HH:mm:ss" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"
          :default-time="['00:00:00', '23:59:59']" />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 操作工具栏 -->
        <el-row :gutter="10" class="mb8">
<!--          <el-col :span="1.5">
            <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                       v-hasPermi="['pekingfish:check-warehouse:create']">新增</el-button>
          </el-col>-->
          <el-col :span="1.5">
            <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" :loading="exportLoading"
                       v-hasPermi="['pekingfish:check-warehouse:export']">导出</el-button>
          </el-col>
          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

    <!-- 列表 -->
    <el-table v-loading="loading" border :data="list">
      <!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
              <template v-slot="scope">
                <el-button size="mini" type="text" @click="handleUpdate(scope.row)"
                           v-hasPermi="['pekingfish:check-warehouse:update']">编辑</el-button>
                <el-button size="mini" type="text"  @click="doSomthing(scope.row,1)"
                           v-hasPermi="['pekingfish:check-warehouse:deduct']">扣款</el-button>
                <el-button size="mini" type="text" @click="doSomthing(scope.row,2)"
                           v-hasPermi="['pekingfish:check-warehouse:return']">退货</el-button>
                <el-button size="mini" type="text" @click="doSomthing(scope.row,3)"
                           v-hasPermi="['pekingfish:check-warehouse:inbound']">入库</el-button>
              </template>
            </el-table-column>-->
      <el-table-column label="操作" align="center" width="160" class-name="small-padding fixed-width">
        <template v-slot="scope">
          <el-button size="mini" type="text" @click="handleUpdate(scope.row)" v-hasPermi="['pekingfish:check-warehouse:update']" v-if="scope.row.status =='wait'">编辑
          </el-button>
          <el-button size="mini" type="text" @click="doSomthing(scope.row,4)" v-hasPermi="['pekingfish:check-warehouse:deductPoint']" v-if="scope.row.status =='wait'">扣积分
          </el-button>
          <el-button size="mini" type="text" @click="doSomthing(scope.row,1)" v-hasPermi="['pekingfish:check-warehouse:deduct']" v-if="scope.row.status =='wait'">扣款
          </el-button>
          <el-button size="mini" type="text" @click="doSomthing(scope.row,2)" v-hasPermi="['pekingfish:check-warehouse:return']" v-if="scope.row.status =='wait'">退货
          </el-button>
          <el-button size="mini" type="text" @click="doSomthing(scope.row,3)" v-hasPermi="['pekingfish:check-warehouse:inbound']" v-if="scope.row.status =='wait' || scope.row.status =='deductPoints' || scope.row.status =='deduction'">入库
          </el-button>
          <el-button size="mini" type="text" @click="handleView(scope.row,scope.index)" v-hasPermi="['pekingfish:check-warehouse:detail']">详细
          </el-button>
          <!--          <el-dropdown  @command="(command) => handleCommand(command, scope.$index, scope.row)"
                                  v-hasPermi="['pekingfish:check-warehouse:deduct', 'pekingfish:check-warehouse:return', 'pekingfish:check-warehouse:inbound']">
                      <el-button size="mini" type="text" icon="el-icon-d-arrow-right">更多</el-button>
                      <el-dropdown-menu slot="dropdown">
                        <el-dropdown-item command="deductMoney" size="mini" type="text"
                                          v-hasPermi="['pekingfish:check-warehouse:deduct']">扣款</el-dropdown-item>
                        <el-dropdown-item command="returnGoods" size="mini" type="text"
                                          v-hasPermi="['pekingfish:check-warehouse:return']">退货</el-dropdown-item>
                        <el-dropdown-item command="inbound" size="mini" type="text"
                                          v-hasPermi="['pekingfish:check-warehouse:inbound']" v-if="scope.row.status='in'">入库</el-dropdown-item>
                      </el-dropdown-menu>
                    </el-dropdown>-->
        </template>
      </el-table-column>

      <el-table-column label="商品二维码" align="center" prop="headImg" min-width="150px">
        <template v-slot="scope">
          <image-preview :src="scope.row.qrCode" :width="40" :height="40"></image-preview>
        </template>
      </el-table-column>
      <el-table-column label="商品编码" align="center" prop="productCode" width="180px" />
      <el-table-column label="订单号" align="center" prop="orderNo" width="200px"/>
      <el-table-column label="商户订单编号" align="center" prop="merchantOrderNo" width="150px" />
      <el-table-column label="验机状态" align="center" prop="status">
        <template v-slot="scope">
          <dict-tag :type="DICT_TYPE.inspection_status" :value="scope.row.status" />
        </template>
      </el-table-column>

      <el-table-column label="手机品牌" align="center" prop="brand" />
      <el-table-column label="手机型号" align="center" prop="model" width="150px"/>
      <el-table-column label="IMEI" align="center" prop="imei"  width="150px"/>
      <el-table-column label="型号类型" align="center" prop="modelType" width="150px" />
      <!--      <el-table-column label="所在仓库" align="center" prop="warehouseName"/>-->
      <el-table-column label="成本价" align="center" prop="costPrice" />
      <el-table-column label="回收价" align="center" prop="paybackPrice" />
      <el-table-column label="销售回收价" align="center" prop="salePaybackPrice" width="100px" />
      <el-table-column label="扣款金额" align="center" prop="deductionAmount" />
      <el-table-column label="销售人员" align="center" prop="saleUserName" />
      <el-table-column label="入库时间" align="center" prop="inboundTime" width="180">
        <template v-slot="scope">
          <span>{{ parseTime(scope.row.inboundTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="验机人员" align="center" prop="checkUserName" />
      <el-table-column label="验机完成时间" align="center" prop="finishTime" width="180">
        <template v-slot="scope">
          <span>{{ parseTime(scope.row.finishTime) }}</span>
        </template>
      </el-table-column>

    </el-table>
    <!-- 分页组件 -->
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize" @pagination="getList" />

    <!-- 详情 -->
    <el-dialog title="详情" :visible.sync="openDetail" width="800px" append-to-body>
      <el-form ref="form" :model="form" label-width="100px" size="mini">
        <el-row>
          <el-col :span="30">
            <el-form-item label="品牌：">{{ form.brand }}</el-form-item>
          </el-col>
          <el-col :span="30">
            <el-form-item label="手机型号：">{{ form.model }}</el-form-item>
          </el-col>
          <el-col :span="30">
            <el-form-item label="型号类型：">{{ form.modelType }}</el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="IMEI：">{{ form.imei }}</el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="参数：">{{ form.memory }}，{{ form.colour }}，{{ form.buy }}，{{
                form.network
              }}
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="机况：">{{ form.subrackDesc }}</el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="补充说明：">{{ form.subrackOtherDesc }}</el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="openDetail = false">关 闭</el-button>
      </div>
    </el-dialog>

    <!-- 对话框(添加 / 修改) -->
    <el-dialog :title="title" :visible.sync="open" v-dialogDrag width="930px" append-to-body>
      <el-form v-if="open" ref="form" :model="form" :rules="rules" label-width="140px">
        <el-row>
         <el-row>
           <el-col :span="12">
             <el-form-item label="手机品牌" prop="brand">
               <el-input v-model="form.brand" disabled />
               <!--              <el-select v-model="form.brandId" placeholder="请选择品牌名称" clearable size="small">
                               <el-option v-for="dict in brandNameList" :key="parseInt(dict.id)" :label="dict.name" :value="parseInt(dict.id)" />
                             </el-select>-->

             </el-form-item>
           </el-col>
           <el-col :span="12">
             <el-form-item label="手机型号" prop="model">
               <el-input v-model="form.model" disabled />
               <!--              <el-select v-model="form.modelId" placeholder="请选择手机型号" clearable size="small">
                               <el-option v-for="dict in tableData" :key="parseInt(dict.id)" :label="dict.name" :value="parseInt(dict.id)" />
                             </el-select>-->
             </el-form-item>
           </el-col>
         </el-row>
         <el-row>
           <el-col :span="12">
             <el-form-item label="IMEA" prop="imei">
               <el-input v-model="form.imei" />
             </el-form-item>
           </el-col>
           <el-col :span="12">
             <el-form-item label="型号类型" prop="modelTypeId">
               <!--              <el-input v-model="form.modelType" disabled />-->
               <el-select v-model="form.modelTypeId" placeholder="请选择型号类型" clearable style="width: 100%;">
                 <el-option v-for="dict in modelTypeList" :key="parseInt(dict.id)" :label="dict.name" :value="parseInt(dict.id)" />
               </el-select>
             </el-form-item>
           </el-col>
         </el-row>
          <el-col :span="12">
            <el-form-item label="是否正常测试" prop="implosion">
<!--              <el-input v-model="form.implosion" disabled />-->
<!--              <el-select style="width: 100%;" v-model="form.implosion" placeholder="请选择内爆" clearable>
                <el-option v-for="(dict,dictI) in phoneModels.implosion" :key="dictI" :label="dict" :value="dict" />
              </el-select>-->
              <el-select
                @visible-change="getQuestionByCategoryId($event,form.implosionId,'implosion')" style="width: 100%;" v-model="form.implosion" placeholder="请选择是否正常测试" clearable>
                <el-option v-for="dict in question['implosion']" :key="dict.id" :label="dict.name" :value="dict.name" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="内存" prop="memory">
              <el-select style="width: 100%;" v-model="form.memory" placeholder="请选择内存" clearable>
                <el-option v-for="(dict,dictI) in phoneModels.memory" :key="dictI" :label="dict" :value="dict" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="颜色" prop="colour">
              <el-select style="width: 100%;" v-model="form.colour" placeholder="请选择颜色" clearable>
                <el-option v-for="(dict,dictI) in phoneModels.color" :key="dictI" :label="dict" :value="dict" />
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="购买渠道" prop="buy">
              <el-select style="width: 100%;" v-model="form.buy" placeholder="请选择购买渠道" clearable>
                <el-option v-for="(dict,dictI) in phoneModels.buyChannel" :key="dictI" :label="dict" :value="dict" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="网络制式" prop="network">
              <el-select style="width: 100%;" v-model="form.network" placeholder="请选择网络制式" clearable>
                <el-option v-for="(dict,dictI) in phoneModels.networkType" :key="dictI" :label="dict" :value="dict" />
              </el-select>
            </el-form-item>
          </el-col>

<!--          <el-col :span="12">
            <el-form-item label="保修期" prop="warranty"v-if="this.form.showType==2">
              <el-select
                @visible-change="getQuestionByCategoryId($event,form.warrantyId,'warranty')" style="width: 100%;" v-model="form.warranty" placeholder="请选择保修期" clearable>
                <el-option v-for="dict in question['warranty']" :key="dict.id" :label="dict.name" :value="dict.name" />
              </el-select>
            </el-form-item>
          </el-col>-->
          <el-col :span="12">
            <el-form-item label="ID账号锁" prop="idAccountLock">
              <el-select
                @visible-change="getQuestionByCategoryId($event,form.idAccountLockId,'idAccountLock')" style="width: 100%;" v-model="form.idAccountLock" placeholder="请选择ID账号锁" clearable>
                <el-option v-for="dict in question['idAccountLock']" :key="dict.id" :label="dict.name" :value="dict.name" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="边框背板" prop="frame">
              <el-select @visible-change="getQuestionByCategoryId($event,form.frameId,'frame')" style="width: 100%;" v-model="form.frame" placeholder="请选择边框背板" clearable>
                <el-option v-for="dict in question['frame']" :key="dict.id" :label="dict.name" :value="dict.name" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="屏幕外观" prop="screen">
              <el-select @visible-change="getQuestionByCategoryId($event,form.screenId,'screen')" style="width: 100%;" v-model="form.screen" placeholder="请选择屏幕外观" clearable>
                <el-option v-for="dict in question['screen']" :key="dict.id" :label="dict.name" :value="dict.name" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="屏幕显示" prop="screenShow">
              <el-select @visible-change="getQuestionByCategoryId($event,form.screenShowId,'screenShow')" style="width: 100%;" v-model="form.screenShow" placeholder="请选择屏幕显示" clearable>
                <el-option v-for="dict in question['screenShow']" :key="dict.id" :label="dict.name" :value="dict.name" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="指纹功能" prop="fingerprint" v-if="this.form.showType==1 || this.form.showType==3">
              <el-select @visible-change="getQuestionByCategoryId($event,form.fingerprintId,'fingerprint')" style="width: 100%;" v-model="form.fingerprint" placeholder="请选择指纹功能" clearable>
                <el-option v-for="dict in question['fingerprint']" :key="dict.id" :label="dict.name" :value="dict.name" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="摄像头检测" prop="camera" v-if="this.form.showType==1 || this.form.showType==3">
              <el-select @visible-change="getQuestionByCategoryId($event,form.cameraId,'camera')" style="width: 100%;" v-model="form.camera" placeholder="请选择摄像头检测" clearable>
                <el-option v-for="dict in question['camera']" :key="dict.id" :label="dict.name" :value="dict.name" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="转轴检测" prop="shaft"  v-if="this.form.showType==3">
              <el-select @visible-change="getQuestionByCategoryId($event,form.shaftId,'shaft')" style="width: 100%;" v-model="form.shaft" placeholder="请选择转轴检测" clearable>
                <el-option v-for="dict in question['shaft']" :key="dict.id" :label="dict.name" :value="dict.name" />
              </el-select>
            </el-form-item>
          </el-col>


          <el-col :span="12">
            <el-form-item label="机身弯曲" prop="fuselageBending">
              <el-select @visible-change="getQuestionByCategoryId($event,form.fuselageBendingId,'fuselageBending')" style="width: 100%;" v-model="form.fuselageBending" placeholder="请选择机身弯曲" clearable>
                <el-option v-for="dict in question['fuselageBending']" :key="dict.id" :label="dict.name" :value="dict.name" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="开机检测" prop="startingUp">
              <el-select @visible-change="getQuestionByCategoryId($event,form.startingUpId,'startingUp')" style="width: 100%;" v-model="form.startingUp" placeholder="请选择开机检测" clearable>
                <el-option v-for="dict in question['startingUp']" :key="dict.id" :label="dict.name" :value="dict.name" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="触屏检测" prop="touchScreen" v-if="this.form.showType==1 || this.form.showType==3">
              <el-select @visible-change="getQuestionByCategoryId($event,form.touchScreenId,'touchScreen')" style="width: 100%;" v-model="form.touchScreen" placeholder="请选择触屏检测" clearable>
                <el-option v-for="dict in question['touchScreen']" :key="dict.id" :label="dict.name" :value="dict.name" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="通话检测" prop="callNo" v-if="this.form.showType==1 || this.form.showType==3">
              <el-select @visible-change="getQuestionByCategoryId($event,form.callNoId,'callNo')" style="width: 100%;" v-model="form.callNo" placeholder="请选择通话检测" clearable>
                <el-option v-for="dict in question['callNo']" :key="dict.id" :label="dict.name" :value="dict.name" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="侧键检测" prop="tort">
              <el-select @visible-change="getQuestionByCategoryId($event,form.tortId,'tort')" style="width: 100%;" v-model="form.tort" placeholder="请选择侧键检测" clearable>
                <el-option v-for="dict in question['tort']" :key="dict.id" :label="dict.name" :value="dict.name" />
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="wifi/信号检测" prop="signalNo" v-if="this.form.showType==1 || this.form.showType==3">
              <el-select @visible-change="getQuestionByCategoryId($event,form.signalNoId,'signalNo')" style="width: 100%;" v-model="form.signalNo" placeholder="请选择wifi/信号检测" clearable>
                <el-option v-for="dict in question['signalNo']" :key="dict.id" :label="dict.name" :value="dict.name" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="历史维修" prop="history">
              <el-select @visible-change="getQuestionByCategoryId($event,form.historyId,'history')" style="width: 100%;" v-model="form.history" placeholder="请选择历史维修" clearable>
                <el-option v-for="dict in question['history']" :key="dict.id" :label="dict.name" :value="dict.name" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="面容检测" prop="face" v-if="this.form.showType==1 || this.form.showType==3">
              <el-select @visible-change="getQuestionByCategoryId($event,form.faceId,'face')" style="width: 100%;" v-model="form.face" placeholder="请选择面容检测" clearable>
                <el-option v-for="dict in question['face']" :key="dict.id" :label="dict.name" :value="dict.name" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="充电检测" prop="recharge" v-if="this.form.showType==1 || this.form.showType==3">
              <el-select @visible-change="getQuestionByCategoryId($event,form.rechargeId,'recharge')" style="width: 100%;" v-model="form.recharge" placeholder="请选择充电检测" clearable>
                <el-option v-for="dict in question['recharge']" :key="dict.id" :label="dict.name" :value="dict.name" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="光感/距离感应检测" prop="sensing" v-if="this.form.showType==1 || this.form.showType==3">
              <el-select @visible-change="getQuestionByCategoryId($event,form.sensingId,'sensing')" style="width: 100%;" v-model="form.sensing" placeholder="请选择光感/距离感应检测" clearable>
                <el-option v-for="dict in question['sensing']" :key="dict.id" :label="dict.name" :value="dict.name" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="重力感应检测" prop="induction" v-if="this.form.showType==1 || this.form.showType==3">
              <el-select @visible-change="getQuestionByCategoryId($event,form.inductionId,'induction')" style="width: 100%;" v-model="form.induction" placeholder="请选择重力感应检测" clearable>
                <el-option v-for="dict in question['induction']" :key="dict.id" :label="dict.name" :value="dict.name" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="指南针检测" prop="compass" v-if="this.form.showType==1 || this.form.showType==3">
              <el-select @visible-change="getQuestionByCategoryId($event,form.compassId,'compass')" style="width: 100%;" v-model="form.compass" placeholder="请选择指南针检测" clearable>
                <el-option v-for="dict in question['compass']" :key="dict.id" :label="dict.name" :value="dict.name" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="闪光灯检测" prop="flash" v-if="this.form.showType==1 || this.form.showType==3">
              <el-select @visible-change="getQuestionByCategoryId($event,form.flashId,'flash')" style="width: 100%;" v-model="form.flash" placeholder="请选择闪光灯检测" clearable>
                <el-option v-for="dict in question['flash']" :key="dict.id" :label="dict.name" :value="dict.name" />
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="24">
            <el-form-item label="机况补充说明" prop="subrackDesc">
              <el-input v-model="form.subrackDesc" type="textarea" placeholder="请输入机况说明" />
            </el-form-item>
          </el-col>

        </el-row>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog :title="title1" :visible.sync="deductOpen" v-dialogDrag width="600px" append-to-body>
      <el-form ref="form1" :model="form" :rules="rules1" label-width="140px">
        <el-row>

          <el-col :span="24">
            <el-form-item label="扣除积分" prop="deductPoints" v-if="this.type==4">
              <el-input-number v-model="form.deductPoints" :min="0"></el-input-number>
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item label="员工可用积分：" v-if="this.type==4">{{ form.updShopUserIntegrals }}</el-form-item>
          </el-col>
          <el-col>
            <el-form-item label="子公司可用积分：" v-if="this.type==4">{{ form.updSubTenantIntegrals }}</el-form-item>
          </el-col>
          <el-col>
            <el-form-item label="员工本单积分：" v-if="this.type==4">{{ form.shopUserIntegral }}</el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="子公司本单积分"  v-if="this.type==4">
              {{ form.subTenantIntegral }}
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="扣积分原因" prop="reason"  v-if="this.type==4">
              <el-input type="textarea" v-model="form.reason" placeholder="请输入扣款原因"/>
            </el-form-item>
          </el-col>

<!--          <el-col :span="24">
            <el-form-item label="子公司可用分润：" v-if="this.type==1">{{ form.paybackPrice }}</el-form-item>
          </el-col>-->
          <el-col :span="24">
            <el-form-item label="子公司可用分润：" v-if="this.type==1">{{ form.shopUserPricesVues }}</el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="子公司本单分润：" v-if="this.type==1">{{ form.subTenantPrice }}</el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="店员本单分润：" v-if="this.type==1">{{ form.shopUserPrice }}</el-form-item>
          </el-col>

          <el-col :span="24">
            <el-form-item label="扣款金额" prop="deductionAmount" v-if="this.type==1">
              <el-input-number v-model="form.deductionAmount" placeholder="请输入扣款金额"
                               :min="0" :precision="2"></el-input-number>
            </el-form-item>
          </el-col>

          <el-col :span="24">
            <el-form-item label="扣款原因" prop="reason" v-if="this.type==1">
              <el-input type="textarea" v-model="form.reason" placeholder="请输入扣款原因"/>
            </el-form-item>
          </el-col>

          <el>
            <el-form-item label="回收价：" v-if="this.type==2">
              <el-input v-model="form.recovery"  />
            </el-form-item>
          </el>
          <el-col>
            <el-form-item label="退款金额" prop="deductionAmount" v-if="this.type==2" >
              <el-input-number v-model="form.deductionAmount"
                               :precision="2" disabled
                               :value="form.paybackPrice"></el-input-number>
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item label="本单分润：" v-if="this.type==2">
              <el-input v-model="form.priceTotal" disabled/>
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item label="本单积分：" v-if="this.type==2">
              <el-input v-model="form.integralTotal" disabled/>
             </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="退货原因" prop="reason" v-if="this.type==2">
              <el-input v-model="form.reason" placeholder="请输入退货原因" />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="验机视频" prop="videoUrl" v-if="this.type!=3">
              <VideoUpload v-model="form.videoUrl" :value="form.videoUrl" />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="验机图片" prop="videoUrl" v-if="this.type!=3">
              <imageUpload v-model="form.buckleImg" :value="form.buckleImg" :limit="10" class="mall-image"/>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="仓库" prop="warehouseCode" v-if="this.type==3">
              <!--              <select-table mode="dialog" v-model="selectTableVal" :fetchFun="fetchFun" :columns="columns" :props="props"
                                          :query="query" @change="handleChange" :pagination="false">
                            </select-table>-->
              <el-select v-model="form.warehouseCode" placeholder="请选择仓库" clearable size="small" style="width: 100%">
                <el-option v-for="dict in warehouseDatas" :key="dict.code" :label="dict.name" :value="dict.code" />
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="24">
            <el-form-item label="机况类型" prop="conditionTypeCode" v-if="this.type==3">
              <el-select  style="width: 100%;" v-model="form.conditionTypeCode"
                         placeholder="请选择机况类型" clearable>
                <el-option v-for="dict in getDictDatas(DICT_TYPE.condition_type
            )" :key="dict.value" :label="dict.label" :value="dict.value"/>
              </el-select>
            </el-form-item>
          </el-col>

        </el-row>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm1">确 定</el-button>
        <el-button @click="cancel1">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import {
  deductPoint,
  deductMoney,
  returnGoods,
  inbound,
  createCheckWarehouse,
  updateCheckWarehouse,
  deleteCheckWarehouse,
  getCheckWarehouse,
  getCheckWarehousePage,
  exportCheckWarehouseExcel
} from "@/api/pekingfish/checkWarehouse";
import { DICT_TYPE, getDictDatas } from "@/utils/dict";
import { getWarehouseList } from "@/api/pekingfish/warehouse";
import SelectTable from '@/components/select-table/index.vue'
import ImagePreview from '@/components/ImagePreview';
import VideoUpload from "@/components/VideoUpload";
import ImageUpload from '@/components/ImageUpload'

import { phoneModelsByParam,getAllPhoneBrand,
  getPhoneModelTable } from "@/api/configuration/phoneModel";
import { questionByCategoryId } from "@/api/configuration/questionType";


export default {
  name: "CheckWarehouse",
  components: {
    SelectTable, ImagePreview, VideoUpload, ImageUpload
  },
  data() {
    return {
      openDetail: false,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 验机仓列表
      list: [],
      // 弹出层标题
      title: "",
      title1: "",
      // 是否显示弹出层
      open: false,
      deductOpen: false,
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        createTime: [],
        orderId: null,
        orderNo: null,
        costPrice: null,
        paybackPrice: null,
        inboundTime: [],
        finishTime: [],
        checkUserName: null,
        status: null,
        type: null,
        deductionAmount: null,
        reason: null,
        fileId: null,
        merchantOrderNo: null,
        salePaybackPrice: null,
        saleUserId: null,
        saleUserNo: null,
        saleUserName: null,
        checkUserId: null,
        checkUserNo: null,
        brandId: null,
        modelId: null,
        modelTypeId: null,
        implosionId: null,
        colourId: null,
        memoryId: null,
        buyId: null,
        networkId: null,
        warrantyId: null,
        idAccountLockId: null,
        frameId: null,
        screenId: null,
        mainboardId: null,
        screenShowId: null,
        cameraId: null,
        startingUpId: null,
        alityId: null,
        imei: null,
        reportImg: null,
        subrackDesc: null,
        productCode: null,
        warehouseCode: null,
        warehouseName: null,
      },
      // 表单参数
      form: {
        id: "",
        warehouseCode: "",
        conditionTypeCode:""
      },
      modelTypeList: [
        { name: "非折叠", id: 1 },
        { name: "折叠屏", id: 2 },
      ],
      // 表单校验
      rules: {
        orderId: [{ required: true, message: "订单id不能为空", trigger: "blur" }],
        orderNo: [{ required: true, message: "订单编号不能为空", trigger: "blur" }],
        merchantOrderNo: [{ required: true, message: "商户订单编号不能为空", trigger: "blur" }],
        conditionTypeCode: [{ required: true, message: "机况类型不能为空", trigger: "blur" }],
      },
      rules1: {
        deductionAmount: [{ required: true, message: "扣款金额不能为空", trigger: "blur" }],
       // reason: [{ required: true, message: "扣款退货原因不能为空", trigger: "blur" }],
        videoUrl: [{ required: true, message: "验机视频不能为空", trigger: "blur" }],
        warehouseCode: [{ required: true, message: "仓库不能为空", trigger: "blur" }],
      },
      // 数据字典
      statusDictDatas: getDictDatas(DICT_TYPE.inspection_status),
      type: "",
      // --下拉表格----
      selectTableVal: null,
      columns: [
        { prop: 'code', label: '仓库编码' },
        { prop: 'name', label: '仓库名称' }
      ],
      props: {
        label: 'name',
        value: 'code',
      },
      query: [{ prop: 'code', label: '仓库编码' }, { prop: 'name', label: '仓库名称' }],
      fetchFun: getWarehouseList,
      warehouseDatas: [],
      phoneModels: {
        memory: [],
        color: [],
        buyChannel: [],
        networkType: []
      },
      question: {

      },
      brandNameList: [],
      tableData: [],
    };
  },
  created() {
    this.getList();
    this.getBrandNameList();
    this.getTableData();
    /* getWarehouseList().then(response => {
       this.users = response.data;
     });*/
    // 获得仓库列表
    getWarehouseList().then(response => {
      this.warehouseDatas = response.data
    })
  },
  methods: {

    async getBrandNameList() {
      const { data } = await getAllPhoneBrand();
      this.brandNameList = data;
    },
    async getTableData() {
      const { data } = await getPhoneModelTable(this.queryParams);
      this.tableData = data.list;
      //this.total = data.total;
    },
    // 获取手机内参数如 颜色 内容
    getPhoneModelsByParam(row) {
      phoneModelsByParam({
        name: row.model
      }).then(response => {
        let data = response.data[0]
        this.phoneModels.memory = data.memory.filter(item => item !== '');
        this.phoneModels.color = data.color.filter(item => item !== '');
        this.phoneModels.buyChannel = data.buyChannel.filter(item => item !== '');
        this.phoneModels.networkType = data.networkType.filter(item => item !== '');
      })
    },
    // 根据问题分类id获取问题列表
    getQuestionByCategoryId(e, id, list) {
      if (e) {
        questionByCategoryId({ categoryId: id }).then(res => {
          this.$set(this.question,list,res.data)
        })
      }
    },

    // selectTable 获取选中的数据
    handleChange(val) {
      this.form.userId = val.id;
      this.form.userNo = val.userNo;
      this.form.userName = val.userName;
    },
    /** 查询列表 */
    getList() {
      this.loading = true;
      // 执行查询
      getCheckWarehousePage(this.queryParams).then(response => {
        this.list = response.data.list;
        this.total = response.data.total;
        this.loading = false;
        this.$forceUpdate()
      });
    },
    /** 取消按钮 */
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 表单重置 */
    reset() {
      this.form = {
        id: undefined,
        orderId: undefined,
        orderNo: undefined,
        costPrice: undefined,
        paybackPrice: undefined,
        inboundTime: undefined,
        finishTime: undefined,
        checkUserName: undefined,
        status: undefined,
        type: undefined,
        deductionAmount: undefined,
        reason: undefined,
        fileId: undefined,
        merchantOrderNo: undefined,
        salePaybackPrice: undefined,
        saleUserId: undefined,
        saleUserNo: undefined,
        saleUserName: undefined,
        checkUserId: undefined,
        checkUserNo: undefined,
        brandId: undefined,
        modelId: undefined,
        modelTypeId: undefined,
        implosionId: undefined,
        colourId: undefined,
        memoryId: undefined,
        buyId: undefined,
        networkId: undefined,
        warrantyId: undefined,
        idAccountLockId: undefined,
        frameId: undefined,
        screenId: undefined,
        mainboardId: undefined,
        screenShowId: undefined,
        cameraId: undefined,
        startingUpId: undefined,
        alityId: undefined,
        imei: undefined,
        reportImg: undefined,
        subrackDesc: undefined,
        productCode: undefined,
        warehouseCode: undefined,
        warehouseName: undefined,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加验机仓";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id;
      this.getPhoneModelsByParam(row);
      getCheckWarehouse(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改验机仓";
        if (this.form.modelType== "直屏"&&this.form.implosion== "无内爆"){
          this.form.showType=1;
        }else if (this.form.implosion== "有内爆"){
          this.form.showType=2;
        }else if (this.form.modelType== "折叠屏"&&this.form.implosion== "无内爆"){
          this.form.showType=3;
        }
        console.log("this.form:",this.form)
      });
    },

    /** 扣款按钮操作 */
    doSomthing(row, type) {
      //  this.reset();
      this.type = type;
      this.form.id = row.id;
      this.form.warehouseCode = row.warehouseCode;
      this.form.paybackPrice = row.paybackPrice;

      this.reset()
      const id = row.id
      getCheckWarehouse(id).then(response => {
        this.form = response.data

        if (type == 1) {
          this.openDeductMoney = true
          this.title1 = "商品扣款";
          this.form.status = "deduction";
        } else if (type == 2) {
          this.title1 = "商品退货";
          this.form.status = "returned";
          this.form.deductionAmount = row.paybackPrice;
          this.form.priceTotal = row.priceTotal;
        } else if (type == 3) {
          this.title1 = "入库";
          this.form.status = "in";
        } else if (type == 4) {
          this.title1 = "扣积分";
          this.form.status = "deductionPoint";
          this.form.merchantOrderNo = row.merchantOrderNo;
        }
      })

      this.deductOpen = true;
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (!valid) {
          return;
        }
        // 修改的提交
        if (this.form.id != null) {
          updateCheckWarehouse(this.form).then(response => {
            this.$modal.msgSuccess("修改成功");
            this.open = false;
            this.getList();
          });
          return;
        }
        // 添加的提交
        createCheckWarehouse(this.form).then(response => {
          this.$modal.msgSuccess("新增成功");
          this.open = false;
          this.getList();
        });
      });
    },


    /** 扣款提交按钮 */
    submitForm1() {
      this.$refs["form1"].validate(valid => {
        if (!valid) {
          return;
        }
        console.log("this.form.status:", this.form.status)
        if (this.form.status == "deduction") {
          deductMoney(this.form).then(response => {
            this.$modal.msgSuccess("扣款成功");
            this.deductOpen = false;
            this.getList();
          });
          return;
        } else if (this.form.status == "returned") {
          returnGoods(this.form).then(response => {
            this.$modal.msgSuccess("退货成功");
            this.deductOpen = false;
            this.getList();
          });
          return;
        } else if (this.form.status == "deductionPoint") {
          deductPoint(this.form).then(response => {
            this.$modal.msgSuccess("扣积分");
            this.deductOpen = false;
            this.getList();
          });
        } else if (this.form.status == "in") {
          inbound(this.form).then(response => {
            this.$modal.msgSuccess("入库成功");
            this.deductOpen = false;
            this.getList();
          });
        }
      });
    },
    /** 扣款取消按钮 */
    cancel1() {
      this.deductOpen = false;
      this.reset();
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const id = row.id;
      this.$modal.confirm('是否确认删除验机仓编号为"' + id + '"的数据项?').then(function () {
        return deleteCheckWarehouse(id);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      // 处理查询参数
      let params = { ...this.queryParams };
      params.pageNo = undefined;
      params.pageSize = undefined;
      this.$modal.confirm('是否确认导出所有验机仓数据项?').then(() => {
        this.exportLoading = true;
        return exportCheckWarehouseExcel(params);
      }).then(response => {
        this.$download.excel(response, '验机仓.xls');
        this.exportLoading = false;
      }).catch(() => {
      });
    },
    // 更多操作
    handleCommand(command, index, row) {
      switch (command) {
        case 'deductMoney':
          this.doSomthing(row, 1);//扣款
          break;
        case 'returnGoods':
          this.doSomthing(row, 2);//退货
          break;
        case 'inbound':
          this.doSomthing(row, 3);//入库
          break;
        default:
          break;
      }
    },

    handleView(row) {
      this.openDetail = true
      this.form = row
    },
  }
};
</script>
